<?php
namespace app\service;

use think\facade\Filesystem;

class Tool{
    /**
     * @param Object $images 上传图片的form标签name
     * @param Srting $repsition 上传的图片地址
     */
    public static function uploadImg($images , $reposition = 'article')
    {
        // $images = request()->file($field);
        if (!empty($images)) {
            $path = Filesystem::disk('images')->putFile($reposition, $images);
            // request()->domain() . 
            $path = str_replace('\\', '/', $path);
            $path = "/static/images/" . $path;
            $data = [
                "errno" => 0,
                'data' => [
                    'url' => $path,
                    'alt' => $path,
                    'href' => $path,
                ]
            ];
            return json($data);
        }
    }
}